package com.class06.mapper.impl;

import com.class06.mapper.StudentMapper;
import com.class06.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class StudentMapperImpl implements StudentMapper {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public Student queryStudentById(Integer id) {
        String sql = "select * from students where id = ?";
        Student student = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Student.class), id).get(0);
        return student;

    }

    @Override
    public List<Student> queryAllStudents() {
        String sql = "select * from students";
        List<Student> studentList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Student.class));
        return studentList;

    }
}
